package db

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

type MysqlConfig struct {
	Host     string
	Port     string
	Database string
	Username string
	Password string
	Charset  string
}

func (c *MysqlConfig) connect() *gorm.DB {
	connectString := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=%s&parseTime=True&loc=Local", c.Username, c.Password, c.Host, c.Port, c.Database, c.Charset)
	db, err := gorm.Open(mysql.Open(connectString), &gorm.Config{})
	if err != nil {
		panic(err)
	}

	return db
}
